package com.linzm.leetcode.mid.tree.递归遍历;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author zimingl
 * @Date 2023/2/19 12:53
 * @Description: 二叉树的中序遍历
 */
public class InorderTraversal_LC94 {
    public static void main(String[] args) {
        InorderTraversal_LC94 inorderTraversal_LC94 = new InorderTraversal_LC94();
        List<Integer> list = inorderTraversal_LC94.inorderTraversal(TreeNode.getTree());
        System.out.println(list);
    }

    private List<Integer> inorderTraversal(TreeNode root) {
        List<Integer> result = new ArrayList<>();
        inorder(root, result);
        return result;
    }

    private void inorder(TreeNode root, List<Integer> result) {
        if (root == null) {
            return;
        }
        inorder(root.left, result);
        result.add(root.val);
        inorder(root.right, result);
    }
}
